#include<bits/stdc++.h>
using namespace std;

// 【题目】力扣.0540 有序数组中的单一元素
// 【难度】中等
// 【提交】https://leetcode.cn/problems/single-element-in-a-sorted-array/submissions/669079320/?envType=problem-list-v2&envId=binary-search
// 【标签】数组；二分查找

class Solution {
public:
    int singleNonDuplicate(vector<int>& nums) {
        int low = 0, high = nums.size() - 1;
        while (low < high) {
            int mid = (high - low) / 2 + low;
            if (nums[mid] == nums[mid ^ 1]) {
                low = mid + 1;
            } else {
                high = mid;
            }
        }
        return nums[low];
    }
};
